<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // let img = new Image();
        // img.src = "./1.jpg"

        // img.onload = function(){
        //     console.log("图片加载成功");
        // }
        // img.onerror = function(){
        //     console.log("图片加载失败");
        // }

        

        function Img(path){
            return new Promise((resolve,reject) =>{
                let img = new Image();
                img.src = path;
                img.onload = function(params){
                    resolve(img);
                }
                img.onerror = function(params){
                    reject("出错了")
                }
            })
        }

        // let a=Img("./1.jpg")
        // console.log(a);
        // console.log(Img("./1.jpg"))
        Img("./1.jpg").then((result) =>{
            // 这里打印最好不要写加号，会隐式转换为字符串tostring,最好写逗号
            console.log("resolve传递给result的结果" , result);
        },(error) =>{
            console.log("resolve传递给result的结果" , error);
        })
    </script>
</body>
</html>